import { BaseWindow } from "../../../component/window/BaseWindow";
import { ILayer } from "../../../mvc/interfaces/ILayer";
import { Language } from "../../../../extend/language/Language";
import { SCountryMoneyCopyRank } from "../../../../Message/Public/SCountryMoneyCopyRank";
import { GameProxy } from "../../mvc/GameProxy";
import { ObjCreate } from "../common/ObjCreate";
import { PageSelecter } from "../common/pageSelect/PageSelecter";
import { CountryMoneyRankCellRender } from "./render/CountryMoneyRankCellRender";
import { DataProvider } from "../../../../fl/data/DataProvider";
import { CountryMoneyRankData } from "./data/CountryMoneyRankData";
import { SCountryMoneyPlayer } from "../../../../Message/Public/SCountryMoneyPlayer";
import { GTabBar } from "../../../../com/mui/controls/GTabBar";
import { GTileList } from "../../../../com/mui/controls/GTileList";
type int = number;
//class CountryMoneyRankWin
    
    export  class CountryMoneyRankWin extends BaseWindow
    {
        constructor(arg1: ILayer=null)
        {
            super(arg1);
            this.Index2Name = ["gold", "coin", "box"];
            this._typeNames = Language.getArrayByStr(80457);
            setSize(455, 484);
            title = Language.getString(44521);
            titleHeight = 47;
            this.configEventListener(flash.events.Event.ADDED_TO_STAGE, this.tabBarChangeHandler);
            return;
        }

        public updateData(arg1: SCountryMoneyCopyRank): void
        {
            this._pageSelector.currentPage = arg1.targetPage;
            this._pageSelector.maxPage = arg1.totalPage;
            this._tab.selectedIndex = (arg1.type - 1);
            this._list.dataProvider = this.parseData(arg1.countryMoneyPlayers);
            this._list.drawNow();
            return;
        }

        public /* override */ dispose(arg1: Boolean=true): void
        {
            super.dispose(arg1);
            if (this._tab != null) 
            {
                this._tab.dispose(arg1);
                this._tab = null;
            }
            if (this._list != null) 
            {
                this._list.dispose(arg1);
                this._list = null;
            }
            if (this._pageSelector != null) 
            {
                this._pageSelector.dispose(arg1);
                this._pageSelector = null;
            }
            return;
        }

        /* internal  */tabBarChangeHandler(arg1=null): void
        {
            GameProxy.copy.getCountryMoneyCopyRank(this._tab.selectedIndex + 1, 10, this._pageSelector.currentPage);
            return;
        }

        protected /* override */ createChildren(): void
        {
            super.createChildren();
            ObjCreate.createBg(14, 55, 427, 422, this);
            this._tab = ObjCreate.createGTabBar(30, 33, Language.getArray(80458), 70, 22, this, this.tabBarChangeHandler);
            this._pageSelector = ObjCreate.createPageSelecter(170, 441, this, PageSelecter.CompleteMode);
            this._pageSelector.configEventListener(flash.events.Event.CHANGE, this.tabBarChangeHandler);
            this._list = ObjCreate.createTileList(20, 55, 424, 424, this);
            this._list.columnWidth = 420;
            this._list.rowHeight = 33;
            this._list.setStyle("cellRenderer", CountryMoneyRankCellRender);
            return;
        }

        /* internal  */parseData(arg1: Array<any>): DataProvider
        {
            var loc2=null;
            var loc6=null;
            if (this._headData == null) 
            {
                this._headData = new CountryMoneyRankData();
                this._headData.rank = this._typeNames[0];
                this._headData.name = this._typeNames[1];
            }
            this._headData.value = this._typeNames[this._tab.selectedIndex + 2];
            var loc1=[];
            var loc3=0;
            if (arg1 != null) 
            {
                loc3 = arg1.length;
            }
            var loc4=0;
            while (loc4 < loc3) 
            {
                if ((loc6 = arg1[loc4] as SCountryMoneyPlayer) != null) 
                {
                    loc2 = new CountryMoneyRankData();
                    loc2.name = loc6.name;
                    loc2.value = loc6[this.Index2Name[this._tab.selectedIndex].toString()];
                    loc1.push(loc2);
                }
                ++loc4;
            }
            loc1.sort(this.sortRank);
            loc4 = 0;
            while (loc4 < loc1.length) 
            {
                loc2 = loc1[loc4];
                loc2.rank = (loc4 + 1).toString();
                ++loc4;
            }
            var loc5;
            (loc5 = new DataProvider(loc1)).addItemAt(this._headData, 0);
            return loc5;
        }

        /* internal  */sortRank(arg1: CountryMoneyRankData, arg2: CountryMoneyRankData): int
        {
            if (parseInt(arg1.value) < parseInt(arg2.value)) 
            {
                return 1;
            }
            return -1;
        }

        /* internal */ /* var */_tab: GTabBar;

        /* internal */ /* var */_list: GTileList;

        /* internal */ /* var */_pageSelector: PageSelecter;

        public /* var */Index2Name: Array<any>;

        /* internal */ /* var */_headData: CountryMoneyRankData;

        /* internal */ /* var */_typeNames: Array<any>;
    }
